package org.niu.tree;

public class HasSumPath {
    boolean flag = false;
    public boolean hasPathSum (TreeNode root, int sum) {
        // write code here
        dfs(root,sum,0);
        return flag;

    }
    void dfs(TreeNode root,int sum,int curSum){
        if(root == null){
            return;
        }
        if(root.left==null&&root.right==null){
            if(curSum+root.val == sum){
                flag = true;
            }
            return;
        }
        dfs(root.left,sum,curSum+root.val);
        dfs(root.right,sum,curSum+root.val);
    }
}
